<?php

namespace Unl\HomologacionBundle\Entity;

//use FOS\UserBundle\Entity\User as BaseUser;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
use FOS\UserBundle\Entity\User as BaseUser;
use Symfony\Component\Validator\ExecutionContext;


/**
* @ORM\Entity(repositoryClass="Unl\HomologacionBundle\Repository\UsuarioRepository")
* @Assert\Callback(methods={"esMailValido"})
*/
class Usuario extends BaseUser
{
    
      
    
    /**
    * @ORM\Id
    * @ORM\Column(type="bigint")
    * @ORM\GeneratedValue(strategy="AUTO")
    */
    protected $id;
 

    /**
    * @ORM\OneToOne(targetEntity="Persona", inversedBy="usuario", cascade={"persist"})
    */
   
    protected $persona;

    public function __construct()
    {
        
       parent::__construct();
       $this->roles = array();
      
       //$this->persona = new Persona();
//     $this->roles = new \Doctrine\Common\Collections\ArrayCollection();   // your own logic
    }
   
    
    /**
     * Get id
     *
     * @return bigint 
     */
    public function getId()
    {
        return $this->id;
    }

//   
//    /**
//     * Set nombreUsuario
//     *
//     * @param string $nombreUsuario
//     */
//    public function setNombreUsuario($nombreUsuario)
//    {
//        $this->nombreUsuario = $nombreUsuario;
//    }
//
//    /**
//     * Get nombreUsuario
//     *
//     * @return string 
//     */
//    public function getNombreUsuario()
//    {
//        return $this->nombreUsuario;
//    }

//    /**
//     * Add roles
//     *
//     * @param Unl\HomologacionBundle\Entity\Rol $roles
//     */
//    public function addRol(\Unl\HomologacionBundle\Entity\Rol $roles)
//    {
//        $this->roles[] = $roles;
//    }
//
//    /**
//     * Get roles
//     *
//     * @return Doctrine\Common\Collections\Collection 
//     */
//    public function getRoles()
//    {
//        return $this->roles;
//    }

    /**
     * Set persona
     *
     * @param Unl\HomologacionBundle\Entity\Persona $persona
     */
    public function setPersona($persona)
    {
        $this->persona = $persona;
    }

    /**
     * Get persona
     *
     * @return Unl\HomologacionBundle\Entity\Persona 
     */
    public function getPersona()
    {
        return $this->persona;
    }
    
    public function getEnabled()
    {
        return $this->enabled;
    }
    
    public function addRole( $rol )
    {
	array_push($this->roles, $rol);
	
    }
    
    public function tieneRol($r){
        foreach ($this->roles as $role) {
            if($r === $role){
                return true;
            }
        }
        return false;
    }
    
 
    
    public function getRoles()
    {
        return $this->roles ;                
    }
    
    
    public function __toString()
    {
        $roleNames = '';  
        foreach ($this->roles as $role) {
            $roleNames = $roleNames . $role;
        }

        return $this->username;
    }
    
 
 
    public function esMailValido(ExecutionContext $context){
         if (empty($this->email)) {
           $context->addViolation('Debe ingresar Email', array(), null);
           return false;   
        }
        return true;
    }
   

    
    
}

